﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using tmAsk.Common;

namespace tmAsk.Member
{
    public partial class ReQuestion : System.Web.UI.Page
    {

        tmAsk.Data.MakeHtml make = new tmAsk.Data.MakeHtml();
        tmAsk.Data.MakehtmlSQL SQL = new tmAsk.Data.MakehtmlSQL();
        protected void Page_Load(object sender, EventArgs e)
        {
            function.CheckUserLogin();
            string aid = Request.QueryString["id"];
            DataTable dt = SQL.GetList("select a_title,a_content,u_id,a_time,a_state from b_ask where a_id=" + aid).Tables[0];
            if (dt.Rows.Count <= 0)
            {
                Response.Write(function.alert_text(4, "该问题不存在！", ""));
                return;
            }
            if (dt.Rows[0][0].ToString() != "0")
            {
                asktitle.InnerText = dt.Rows[0]["a_title"].ToString();
                askcon.InnerHtml = dt.Rows[0]["a_content"].ToString();
                username.InnerText = GetUserName(dt.Rows[0]["u_id"].ToString());
                usertime.InnerText = dt.Rows[0]["a_time"].ToString();
            }
            int pageindex = 1;  //页码
            int page = 3;       //每页条数
            int pagecount = 1;  //总页数
            int count = 0;        //共多少条
            if (!string.IsNullOrEmpty(Request.QueryString["page"]))
            {
                try
                {
                    pageindex = Convert.ToInt32(Request.QueryString["page"]);
                }
                catch
                { }
            }
            DataSet ds = SQL.GetList("B_review", "r_id", page, pageindex, "r_id asc", 1, "a_id=" + aid);
            ds.Tables[0].Columns.Add("a_state");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                DataTable dtState = SQL.GetList("select a_state from b_ask where a_id=" + ds.Tables[0].Rows[0]["a_id"]).Tables[0];
                ds.Tables[0].Rows[i]["a_state"] = dtState.Rows[0][0];
            }

            rptReQuestion.DataSource = ds;
            rptReQuestion.DataBind();
            DataSet ds2 = SQL.GetList("B_review", "a_id=" + aid, "r_id");
            if ((ds2.Tables[0].Rows.Count % page) > 0)
            {
                pagecount = ds2.Tables[0].Rows.Count / page + 1;
            }
            else
            {
                pagecount = ds2.Tables[0].Rows.Count / page;
            }

            count = ds2.Tables[0].Rows.Count;
            lblTxt.Text = make.htmlpage(count, page, pageindex, "?", "id=" + aid + "&page=");
        }

        public string GetUserName(object uid)
        {
            string username = "";
            DataTable dt = SQL.GetList("select u_nickName from b_user where u_id=" + uid).Tables[0];
            if (dt.Rows.Count > 0)
            {
                username = dt.Rows[0][0].ToString();
            }
            return username;
        }

        public string DelReQuestion(object uid)
        {
            Response.Write(function.alert_text(4, uid.ToString(), ""));
            return uid.ToString();
        }
    }
}